package com.kd.juhaowan.ui.holder;

import android.annotation.SuppressLint;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.flyjingfish.shapeimageviewlib.ShapeImageView;
import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.GameModel;
import com.kd.juhaowan.ui.adapter.BaseViewHolder;
import com.kd.juhaowan.utils.GlideHelper;
import com.kd.juhaowan.utils.LogUtil;


import net.lucode.hackware.magicindicator.buildins.UIUtil;

import butterknife.BindView;

public class CateGameViewHolder extends BaseViewHolder {



    @BindView(R.id.item_image)
    ShapeImageView imageView;

    @BindView(R.id.item_name)
    TextView nameView;


    @BindView(R.id.item_star)
    TextView starView;
    @BindView(R.id.item_cat)
    TextView catView;
    @BindView(R.id.item_people)
    TextView peopleView;
    @BindView(R.id.item_zhekou_layout)
    LinearLayout zhekouLayout;
    @BindView(R.id.item_zhekou_text)
    TextView zhekouText;


    @BindView(R.id.gamelist_tag)
    LinearLayout tagListview;

    @BindView(R.id.catGame_rank_number)
    TextView rankText;
    @BindView(R.id.catGame_rank_image)
    ImageView rankImage;

//    private BaseRecyclerViewAdapter<FollowHeadViewHolder, String> searchHistoryAdapter;
    private LinearLayout.LayoutParams params;


    public CateGameViewHolder(@NonNull View itemView) {
        super(itemView);
        params =new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.rightMargin= UIUtil.dip2px(getContext(),5);

    }



    @SuppressLint("ResourceType")
    public void setDate(GameModel model, int position){

        if(position==0){
            rankImage.setVisibility(View.VISIBLE);
            rankText.setVisibility(View.GONE);
            rankImage.setImageResource(R.mipmap.icon_categame1);
        }else if (position==1){
            rankImage.setVisibility(View.VISIBLE);
            rankText.setVisibility(View.GONE);
            rankImage.setImageResource(R.mipmap.icon_categame2);
        }else if (position==2){
            rankImage.setVisibility(View.VISIBLE);
            rankText.setVisibility(View.GONE);
            rankImage.setImageResource(R.mipmap.icon_categame3);
        }else {
            rankImage.setVisibility(View.GONE);
            rankText.setVisibility(View.VISIBLE);
            rankText.setText(String.valueOf(position+1));
        }

        GlideHelper.loadGoodsCover(Glide.with(getItemView()),imageView,model.getLogoimage());
        nameView.setText(model.getName());
        starView.setText(model.getScore());
        catView.setText(model.getCat_name());
        peopleView.setText(model.getPeople_are_playing()+"人在玩");

        if(model.getDiscount()>0){
            zhekouLayout.setVisibility(View.VISIBLE);
            zhekouText.setText(model.getDiscount()+"折直充");
        }else{
            zhekouLayout.setVisibility(View.GONE);
        }

        String[] tags =model.getTags();
        LogUtil.debugLog("dafa"+tags==null?"null":tags.length+"");
        if(tags!=null&&tags.length>0){
            tagListview.setVisibility(View.VISIBLE);
            tagListview.removeAllViews();
            for (String adb:tags) {
                TextView tv=new TextView(getContext());
                tv.setGravity(Gravity.CENTER);
                tv.setBackgroundResource(R.drawable.tag_bg);
                tv.setPadding(UIUtil.dip2px(getContext(),5),0,UIUtil.dip2px(getContext(),5),0);
                tv.setText(adb);
                tv.setTextColor(getContext().getColor(R.color.login_edit_hint));
                tv.setTextSize(11);
                tagListview.addView(tv,params);
            }


//            searchHistoryAdapter.resetAdapterData(Arrays.asList(tags));
        }else {
            tagListview.setVisibility(View.GONE);
        }

    }


}
